#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>

void Arrayprint(int* arr, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%d ",arr[i]);
	}
	printf("\n");
}

void insertsort(int* arr, int n)
{
	for (int i = 0; i < n-1; i++)
	{
		int tem=arr[i+1];
		int end=i;
		while (end >= 0)
		{
			if (arr[end] > tem)
			{
				arr[end + 1] = arr[end];
				end--;
			}
			else
			{
				break;
			}
		}
		arr[end + 1] = tem;
	}
}
void ShellSort(int* arr, int n)
{
	int gap = n;
	while (gap> 1)
	{
		gap = gap / 2;
		for (int i = 0; i < n - gap; i++)
		{

			int tem = arr[i + gap];
			int end = i;
			while (end >= 0)
			{
				if (arr[end] > tem)
				{
					arr[end + gap] = arr[end];
					end-=gap;
				}
				else
				{
					break;
				}
			}
			arr[end + gap] = tem;
		}
	}
}

int main()
{
	int arr[10] = { 5,3,1,8,9,4,2,10,7,6 };
	int i = 0;
	Arrayprint(arr,10);
	//insertsort(arr, 10);
	ShellSort(arr, 10);
	Arrayprint(arr, 10);

	return 0;
}